WorkerScript.onMessage = function(message) {
    var i = 0;
    message.goods.forEach(function(v){
        v.BrandAlias = findBrand(message.brand, v.Brand)
        v.CategoryAlias = findCategory(message.category, v.Category)

        message.source.append(v);

        i++;

        if (i % 5 == 0) {
            WorkerScript.sendMessage({'value': i })
            message.source.sync()
        }
    })

    WorkerScript.sendMessage({'value': message.goods.length })
    message.source.sync()
}


function findBrand(model, id)
{
    for (var i = 0; i < model.count;i++) {
        var d = model.get(i);
        if (id == d.Id)
                return d.Name
    }

    return ""
}

function findCategory(model, id)
{
    for (var i = 0; i < model.count;i++) {
        var d = model.get(i);
        if (id == d.Id)
                return d.Name
    }

    return ""
}
